package com.tools.ad.adscene.inner;

import com.hm.ads.sdk.HmAdsSDK;
import com.hm.adsbuisiness.bean.HmAdUnionPlace;
import com.hm.base.android.mob.AMApplication;
import com.tools.ad.AdType;
import com.tools.ad.EntranceType;
import com.tools.ad.R;

/**
 * 功能 插屏广告
 */
public class FuncInterstitialScene extends CommonInterstitialScene {

    public FuncInterstitialScene(AMApplication context, EntranceType entranceType) {
        super(context, entranceType);
    }

    @Override
    protected void onRequestAllFail() {
        imContext.handleMobEmptyMessage(R.id.msg_ad_interstitial_failed);
    }

    @Override
    protected void onADLoaded(AdType adType) {
        // 广告成功返回，通知界面，显示广告
        imContext.handleMobEmptyMessage(R.id.msg_ad_interstitial_loaded);
    }

    @Override
    protected void onAdClose(AdType adType) {
        super.onAdClose(adType);
        imContext.handleMobEmptyMessage(R.id.msg_ad_interstitial_closed);
    }

    @Override
    protected void onADClick(AdType adType) {
        super.onADClick(adType);
        imContext.handleMobEmptyMessage(R.id.msg_ad_interstitial_closed);
    }

    /**
     * 加载广告
     *
     * @param forceLoad 是否忽略配置检查，强制加载广告
     * @return
     */
    @Override
    public boolean load(boolean forceLoad) {
        HmAdUnionPlace adUnionPlace = HmAdsSDK.getInstance().getUnionAd(mEntranceType.getPid());
        if (adUnionPlace == null) {
            return false;
        }
        mHmAdPlace = adUnionPlace;
        mExecutor = getADModule().getADStrategyManager().getExecutorByEntranceType(mEntranceType);
        if (forceLoad || mExecutor.check(adUnionPlace)) {
            return loadUnionPlace(adUnionPlace);
        }

        return false;
    }

}
